﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DXApplicationTangche.UC.成品出库单.service;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using mendian;

namespace DXApplicationTangche.UC.门店出入库.UC
{
    public partial class UserControl出入库明细一览 : UserControl
    {
        private List<StockInOutDetailDTO> StockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        private List<ViewStockInOutDetailDTO> viewStockInOutDetailDTOs = new List<ViewStockInOutDetailDTO>();
        public UserControl出入库明细一览()
        {
            InitializeComponent();
            refreshGrid();
        }
        /// <summary>
        /// 数据源刷新
        /// </summary>
        public void refreshGrid()
        {
            this.StockInOutDetailDTOs = FunctionHelper.JsonDeserialization<List<StockInOutDetailDTO>>(
                RestCall.httpGetMethod(
                    URL.接口url + "/inventory/getInStockDetailAll"
                    )
                );
            foreach (StockInOutDetailDTO dTO in this.StockInOutDetailDTOs)
            {
                this.viewStockInOutDetailDTOs.Add(new ViewStockInOutDetailDTO(dTO));
            }
            this.pivotGridControl出入库明细一览.DataSource = this.viewStockInOutDetailDTOs;
            this.pivotGridControl出入库明细一览.Refresh();
        }
        /// <summary>
        /// 取得数据源
        /// </summary>
        /// <returns></returns>
        public List<StockInOutDetailDTO> getDataStockInOutDetailDTOs()
        {
            return this.StockInOutDetailDTOs;
        }
    }

    public class ViewStockInOutDetailDTO
    {
        public String barcode { get; set; } //成衣码
        public String batchNo { get; set; } ////批号
        public String styleNameCn { get; set; } // //  款式名称
        public String styleSizeCd { get; set; } ////尺码
        public String fabricId { get; set; } //
        public String fabricCode { get; set; } //面料号
        public String fabricName { get; set; } //面料名称
        public String fabricComposition { get; set; } //面料成分
        public String status { get; set; }//状态
        public DateTime salesTime { get; set; } //
        public int inOutFlag { get; set; } //出入库标识：0出库，1入库
        public String inOutType { get; set; } //出入库类型
        public String storeId { get; set; } //
        public String storeName { get; set; }
        //  货号信息
        public String refStyleId { get; set; } //
        public String inventory { get; set; } //
        public double price { get; set; } //

        public ViewStockInOutDetailDTO(StockInOutDetailDTO stockInOutDetailDTO)
        {
            this.barcode = stockInOutDetailDTO.barcode; //成衣码
            this.batchNo = stockInOutDetailDTO.batchNo;////批号
            this.styleNameCn = stockInOutDetailDTO.styleNameCn; // //  款式名称
            try
            {
                this.styleSizeCd = (stockInOutDetailDTO.styleSizeCd == null) ? stockInOutDetailDTO.styleSizeCd : stockInOutDetailDTO.styleSizeCd.Substring(15); ////尺码
            }
            catch
            {
                this.styleSizeCd = stockInOutDetailDTO.styleSizeCd ; ////尺码
            }

            this.fabricId = stockInOutDetailDTO.fabricId; //
            this.fabricCode = stockInOutDetailDTO.fabricCode; //面料号
            this.fabricName = stockInOutDetailDTO.fabricName; //面料名称
            this.fabricComposition = stockInOutDetailDTO.fabricComposition; //面料成分
            this.salesTime = stockInOutDetailDTO.salesTime; //
            this.inOutFlag = stockInOutDetailDTO.inOutFlag; //出入库标识：0出库，1入库
            this.inOutType = stockInOutDetailDTO.inOutType; //出入库类型
            this.storeId = stockInOutDetailDTO.storeId; //
            this.storeName = stockInOutDetailDTO.storeName;
            //  货号信息
            this.refStyleId = stockInOutDetailDTO.refStyleId; //
            this.inventory = stockInOutDetailDTO.inventory; //
            this.price = stockInOutDetailDTO.price; //
            switch (this.inOutType)
            {
                case "工厂成衣入库":
                    this.status = "在库";
                    break;
                case "门店成衣调拨入库":
                    this.status = "在库";
                    break;
                case "退货入库":
                    this.status = "在库";
                    break;
                case "门店销售出库":
                    this.status = "出库";
                    break;
                case "盘亏出库":
                    this.status = "出库";
                    break;
                case "门店成衣调拨出库":
                    this.status = "在途";
                    break;
                case "工厂销售出库":
                    this.status = "出库";
                    break;
                case "工厂成衣调拨出库":
                    this.status = "在途";
                    break;
                default:
                    this.status = "其他";
                    break;
            }
        }
        public ViewStockInOutDetailDTO()
        {

        }
    }
}
